package com.example.hackotontest;

import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginActivity extends Activity{
	
    private SharedPreferences users;
	public static Typeface tf;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        
        tf = Typeface.createFromAsset(getAssets(),"data/fonts/font.ttf");
        
        TextView tv = (TextView) findViewById(R.id.tv_user);      
        tv.setTypeface(tf);
     
        //check user
       /* users = this.getSharedPreferences("USERS", MODE_WORLD_READABLE);
        if(users.getString("username", null) != null) {
            setContentView(R.layout.activity_menu);
            SharedPreferences.Editor dhjEditor = users.edit();
    		dhjEditor.putString("username", tv.getText().toString());
    		dhjEditor.commit();
        }
        else {
                final String username = ((EditText) findViewById(R.id.et_user)).getText().toString();
                Button  loginButton = (Button) findViewById(R.id.btn_login);
                            
                loginButton.setOnClickListener(new OnClickListener() {
                	  
                    @Override
                    public void onClick(View v) {
                        SharedPreferences.Editor usersEditor = users.edit();
                        usersEditor.putString("username", username);
                                            
                    }
                }); 
               
        }*/
    }
	
	public void loginClick(View view) {
		if (!((EditText) findViewById(R.id.et_user)).getText().toString().isEmpty()){
			Intent i = new Intent(this, UserActivity.class);
			i.putExtra("username", ((EditText) findViewById(R.id.et_user)).getText().toString());
			startActivity(i);
		}
		else{
			makeDialog();
		}
	}
	
	private void makeDialog() {		
		
	    AlertDialog.Builder dialog = new AlertDialog.Builder(this);	    
	    dialog.setMessage("Enter a participant name!");
	
	    dialog.setNegativeButton("Close", new DialogInterface.OnClickListener() {
	        public void onClick(DialogInterface arg0, int arg1) {}
	    });
	
	    dialog.show();
	}
}
